<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<base href="/webcon/resources/"/>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title></title>
		<link rel="stylesheet" href="layui/css/layui.css">
		<link rel="stylesheet" href="css/timing.css">

		<script src="js/jquery-3.5.0.min.js"></script>
		<script src="layui/layui.js"></script>

		<!-- 引入bootstrap -->
		<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"/>
		<script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>

		<!--引入webuploader-->
		<link rel="stylesheet" type="text/css" href="widget/webuploader/webuploader.css">
		<script type="text/javascript" src="widget/webuploader/webuploader.min.js"></script>

		<!-- 引入ztree -->
		<link rel="stylesheet" href="widget/zTree/zTreeStyle/zTreeStyle.css"/>
		<script type="text/javascript" src="widget/zTree/jquery.ztree.all.min.js"></script>

		<!-- 自定义js -->
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/myupload.js'}"></script>
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/myztree.js'}"></script>
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/myajax.js'}"></script>
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/mytask.js'}"></script>
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/task_fire.js'}"></script>
		<script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/mytask_status.js'}"></script>

		<!-- 日期插件 -->
		<link rel="stylesheet"
			  th:href="${#request.getContextPath() + '/system/resources/widget/My97DatePicker/skin/WdatePicker.css'}"
			  type="text/css"/>
		<script type="text/javascript"
				th:src="${#request.getContextPath() + '/system/resources/widget/My97DatePicker/WdatePicker.js'}"></script>


		<script th:inline="javascript">
			$(function () {
				//初始化任务列表
				initFireTask();
			});
		</script>
	</head>
	<body>
		<div class="header">
			<div class="list-item" onclick="openModal(0)">
				<div class="list-item-top">
					<img src="./img/xinjian.png" />
				</div>
				<div class="desc">新建任务</div>
			</div>
			<div class="list-item" onclick="openModal(1)">
				<div class="list-item-top">
					<img src="./img/bianji.png" />
				</div>
				<div class="desc">编辑任务</div>
			</div>
			<div class="list-item" onclick="copy_task(fireHtml);">
				<div class="list-item-top">
					<img src="./img/fuzhi.png" />
				</div>
				<div class="desc">复制任务</div>
			</div>
			<div class="list-item" onclick="isAction(2, 3);">
				<div class="list-item-top">
					<img src="./img/shanchu.png" />
				</div>
				<div class="desc">删除任务</div>
			</div>
			<div class="list-item" onclick="action_task();">
				<div class="list-item-top">
					<img src="./img/bofang.png" />
				</div>
				<div class="desc">手动执行</div>
			</div>
			<div class="list-item" onclick="stop_task();">
				<div class="list-item-top">
					<img src="./img/tingzhi.png" />
				</div>
				<div class="desc">手动停止</div>
			</div>
		</div>

		<table class="layui-table">
			<thead>
			<tr>
				<th>任务名称</th>
				<th>任务状态</th>
				<th>端口号</th>
				<th>报警区域</th>
				<th>邻层报警</th>
				<th>报警曲目</th>
				<th>报警终端</th>
			</tr>
			</thead>
			<tbody id="task_list">
			<!-- TODO 任务列表 -->
			</tbody>
		</table>

		<!-- 新建任务弹出框 -->
		<div id="tt" style="padding:20px 35px;display: none;">
			<div class="item" style="width: 260px;height: 470px;">
				<div style="padding: 10px 10px;">
					<div class="layui-row">
						<div class="layui-col-md4">
							<span class="task-name">任务名称:</span>
						</div>
						<div class="layui-col-md8">
							<input type="text" id="taskname" placeholder="任务名称"
								   required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-row">
						<div class="layui-col-md4">
							<span class="task-name">报警区域:</span>
						</div>
						<div class="layui-col-md8">
							<input type="text" id="area" placeholder="报警区域"
								   required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-row" style="padding-top: 5px;">
						<div class="layui-col-md4">
							<span class="task-name">触发设备:</span>
						</div>
						<div class="layui-col-md8 layui-form">
							<select id="fireTerminal" lay-verify="">
								<option value="1">报警终端(网络)</option>
								<option value="2">报警矩阵(串口)</option>
							</select>
						</div>
					</div>
					<div class="layui-row">
						<div class="layui-col-md4">
							<span class="task-name">设备端口:</span>
						</div>
						<div class="layui-col-md8">
							<input id="port" type="text" placeholder="设备端口"
								   required lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-row" style="padding-top: 5px;">
						<div class="layui-col-md4">
							<span class="task-name">邻层报警:</span>
						</div>
						<div class="layui-col-md8 layui-form">
							<select id="isLevel" lay-verify="">
								<option value="1">关闭</option>
								<option value="2">开启</option>
							</select>
						</div>
					</div>
					<div class="layui-row" style="padding-top: 5px;">
						<div class="layui-col-md4">
							<span class="task-name">报警音源:</span>
						</div>
						<div class="layui-col-md5 layui-form">
							<select id="externalFireTerminal" lay-verify="" disabled="disabled">
							</select>
						</div>
						<div class="layui-col-md2 layui-form" style="text-align: right;">
							<input id="isExternalMusic" type="checkbox" lay-filter="isExternalMusic" lay-skin="switch" lay-text="ON|OFF">
						</div>
					</div>
				</div>
			</div>
			<div class="item item1" style="width: 580px;height: 470px;">
				<div id="picker" class="layui-btn">本地上传</div>
				<button id="upload_btn" class="layui-btn" onclick="start_upload();">
					开始上传
				</button>
				<div id="yun_btn" class="layui-btn" onclick="open_show_yun();">云端选择</div>
				<div style="margin-top: 10px; height: 380px;  overflow: auto;">
					<!--<table class="table">
                        <thead>
                        <tr>
                            <th colspan="2">音乐列表</th>
                        </tr>
                        </thead>
                        <tbody id="upload_list">
                        </tbody>
                    </table>-->
					<h4>音乐列表</h4>
					<ul class="list-group" id="upload_list">
						<li class="list-group-item">Cras justo odio</li>
						<li class="list-group-item">Dapibus ac facilisis in</li>
						<li class="list-group-item">Morbi leo risus</li>
						<li class="list-group-item">Porta ac consectetur ac</li>
						<li class="list-group-item">Vestibulum at eros</li>
					</ul>
				</div>
			</div>
			<div class="item item2" style="height: 470px;">
				<div style="padding-left: 10px;padding-top: 10px;">
					<span>终端列表：</span>
					<input class="selectAll" id="checkbox1" onclick="checkall(this.checked);" style="width: 18px;height: 18px;position: relative;top: 4px;" type="checkbox">
					全选
				</div>
				<!-- 树形选择器 -->
				<div id="ztree_div" class="ztree"
					 style="height: 430px; overflow:scroll; overflow-y: auto; overflow-x: auto;"></div>
			</div>
		</div>

		<!-- 云端列表 -->
		<div id="yunlistdiv" style="display: none;">
			<ul class="list-group" id="yun_upload_list">
			</ul>
		</div>
		
		<script>
			var checked = false
			$(".selectAll").attr("checked", checked)
			layui.use(['table', 'form', 'layer', 'laydate'], function() {
				var table = layui.table;
				var form = layui.form;
				var layer = layui.layer;
				var laydate = layui.laydate;
				//执行一个laydate实例
				laydate.render({
					elem: '#date1' //指定元素
				});

				//监听开关事件
				form.on('switch(isExternalMusic)', function (data) {
					var contexts;
					var x = data.elem.checked;//判断开关状态
					//修改状态
					open_fire(x);
					return true;
				});
			});

			function deleteTer() {
				layer.confirm('确定要删除吗?', {
					icon: 3,
					title: '系统提示'
				}, function(index) {
					layer.close(index);
				});
			}

			function openModal(num) {
				layer.open({
					type: 1,
					area: ['1200px', '650px'],
					title: '消防报警',
					offset: '20px',
					btn: ['确定','取消'],
					shade: 0.6,
					maxmin: false,
					anim: 4,
					content: $("#tt"),
					yes: function(index, layero){
						if(num == 0){
							//提交任务
							submit_task();
						} else if(num == 1){
							//修改任务
							var task = $("[alt='del']")[0];
							var tid = task.getAttribute("taskidstr");
							update_task(tid);
						}
						return true;
					},success: function(layero, index){
						$('body').attr('style','overflow:hidden')

						if(num == 0){
							//创建语音报警任务
							open_Model(3);
						} else if(num == 1){
							//编辑任务
							isAction(1, 3);
						}
					},
					cancel: function(index, layero){
						$('body').removeAttr('style')
					}
				});
			}
			function deleteTask(){
				layer.confirm('确定要删除吗?', {icon: 3, title:'系统提示'}, function(index){
				  //do something
				  
				  layer.close(index);
				});
			}
			function copyTask(){
				layer.confirm('确定要复制吗?', {icon: 3, title:'系统提示'}, function(index){
				  //do something
				  
				  layer.close(index);
				});
			}
		</script>
	</body>
</html>
